﻿package com.wandian.view.components.ui.mingame.zp
{
	import com.wandian.ApplicationFacade;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.vo.PropVo;
	import com.wandian.model.vo.VIPVo;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZLlistScrollPanel;
	import com.wandian.util.CLZLoadIcon;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.CLZZoom;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.ToolTip;

	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	/**   
	* @author long
	* @QQ 108232706
	* @version 1.0   
	*/   
	public class ZPPanel extends Object
	{
		private var _mcPanel:MovieClip;
		private var _nSeletedNum:int;
		private var _rotationLong:Number;
		private var MaxSd:int=40;
		private var MinSd:int=0;
		private var ASd:Number;
		private var Sd:Number=0;
		private var _filter:GlowFilterManage;
		private var _arrResult:Array;
		private var _arrTxt:Array;
		private var _arrMc:Array;
		private var _global:GameData;
		private var facade:ApplicationFacade;

		public function ZPPanel(param1:MovieClip)
		{
			var _loc_3:VIPVo=null;
			this._filter=GlowFilterManage.getInstance();
			this._arrResult=[];
			this._global=GameData.getInstance();
			this.facade=ApplicationFacade.getInstance();
			this._mcPanel=param1;
			this._mcPanel["close_btn"].addEventListener(MouseEvent.CLICK, this.onCloseHandler);
			this._mcPanel.title_txt.text=GameData.tip["ONLINE_REWARD_NAME"];
			var _loc_2:String="";
			switch (this._global.userInfo.userVo.vip)
			{
				case 0:
				{
					_loc_2="0";
					break;
				}
				case 1:
				case 2:
				case 3:
				case 4:
				case 5:
				{
					_loc_3=GameData.getVIPXMLById(this._global.userInfo.userVo.vip + 2);
					_loc_2="VIP" + this._global.userInfo.userVo.vip + "  +" + _loc_3.objContent["4"];
					break;
				}
				default:
				{
					break;
				}
			}
			if (this._global._onLineRewardNum <= 0)
			{
				this._mcPanel.start_btn.filters=this._filter.getGrayscale();
				this._mcPanel.start_btn.mouseEnabled=false;
			}
			else
			{
				this._mcPanel.start_btn.mouseEnabled=true;
				this._mcPanel.start_btn.filters=[];
			}
			this._mcPanel.vipNum_txt.htmlText="<font color=\'#ff0000\'>" + _loc_2 + "</font>";
			this._mcPanel.numTip_txt.htmlText=GameData.replaceStrValue(GameData.tip["ONLINE_NUM_TIP"], "NUM", this._global._onLineRewardNum);
			this._arrTxt=[this._mcPanel.gold1, this._mcPanel.gold2, this._mcPanel.gold3, this._mcPanel.gold4, this._mcPanel.gold5, this._mcPanel.gold6, this._mcPanel.gold7, this._mcPanel.gold8];
			this._arrMc=[this._mcPanel.mc1, this._mcPanel.mc2, this._mcPanel.mc3, this._mcPanel.mc4, this._mcPanel.mc5, this._mcPanel.mc6, this._mcPanel.mc7, this._mcPanel.mc8];
			if (this._global.userInfo.userVo.lotcount >= 6)
			{
				this.updateTxt(2);
			}
			else
			{
				this.updateTxt(1);
			}
			this._mcPanel.start_btn.addEventListener(MouseEvent.CLICK, this.onStartHandler);
			return;
		} 

		private function onCloseHandler(event:MouseEvent):void
		{
			this.facade.sendNotification(CLZNoticeName.HIDE_CLOSE_ZP_PANEL);
			return;
		} 

		public function startGame(param1:Array):void
		{
			var _loc_2:int=0;
			var _loc_3:*=this._global.userInfo.userVo;
			var _loc_4:*=this._global.userInfo.userVo.lotcount + 1;
			_loc_3.lotcount=_loc_4;
			this._arrResult=param1;
			if (this._global.userInfo.userVo.lotcount > 6)
			{
				this._nSeletedNum=this._arrResult[4] - 9;
				if (this._global.userInfo.userVo.lotcount == 7)
				{
					this.updateTxt(2);
				}
			}
			else
			{
				this._nSeletedNum=this._arrResult[4] - 1;
			}
			if (this._mcPanel.roll.rotation == 0)
			{
				this._rotationLong=this.getRotationLong(8, -0.65, 4, 7, this._nSeletedNum, 0.2);
			}
			else
			{
				if (this._mcPanel.roll.rotation < 0)
				{
					_loc_2=180 + (180 + this._mcPanel.roll.rotation);
				}
				else
				{
					_loc_2=this._mcPanel.roll.rotation;
				}
				this._rotationLong=this.getRotationLong(8, -0.65, 4, 7, this._nSeletedNum, 0.2, -_loc_2);
			}
			this.ASd=(this.MaxSd * this.MaxSd - this.MinSd * this.MinSd) / this._rotationLong;
			this.Sd=0;
			this._mcPanel.addEventListener(Event.ENTER_FRAME, this.Onrotation);
			return;
		} 

		private function onStartHandler(event:MouseEvent):void
		{
			if (this._global._onLineRewardNum <= 0)
			{
				return;
			}
			this._mcPanel.start_btn.mouseEnabled=false;
			this._mcPanel.start_btn.filters=this._filter.getGrayscale();
			var _loc_2:*=this._global;
			var _loc_3:*=this._global._onLineRewardNum - 1;
			_loc_2._onLineRewardNum=_loc_3;
			this._mcPanel.numTip_txt.htmlText=GameData.replaceStrValue(GameData.tip["ONLINE_NUM_TIP"], "NUM", this._global._onLineRewardNum);
			this.facade.sendNotification(CLZNoticeName.SGJ_ZP_REQ, 2);
			return;
		} 

		private function Onrotation(param1):void
		{
			var _loc_3:String=null;
			if (this.Sd >= this.MaxSd)
			{
				this.Sd=2 * this.MaxSd - this.Sd;
				this.ASd=-this.ASd;
			}
			var _loc_2:*=int(this.getCureMc(8, this._mcPanel.roll.rotation));
			this._arrMc[_loc_2].gotoAndPlay(2);
			this.Sd=this.Sd + this.ASd;
			if (this.Sd > 0)
			{
				this._mcPanel.roll.rotation=this._mcPanel.roll.rotation + this.Sd;
			}
			else
			{
				this._mcPanel.removeEventListener(Event.ENTER_FRAME, this.Onrotation);
				this._arrMc[this._nSeletedNum].gotoAndStop(2);
				this._mcPanel.start_btn.alpha=1;
				if (this._global._onLineRewardNum <= 0)
				{
					this._mcPanel.start_btn.filters=this._filter.getGrayscale();
				}
				else
				{
					this._mcPanel.start_btn.filters=[];
					this._mcPanel.start_btn.mouseEnabled=true;
				}
				_loc_3="";
				if (this._arrResult[0])
				{
					if (this._arrResult[1] == 1)
					{
						_loc_3=_loc_3 + GameData.replaceStrValue(GameData.tip["GET_SGJ_PRIZE_GOLD"], "NUM", this._arrResult[3]);
						this._global.userInfo.gold=this._arrResult[2];
					}
					else
					{
						_loc_3=_loc_3 + GameData.tip["OTHER_ERR"];
					}
				}
				if (this._global.userInfo.userVo.lotcount > 6)
				{
					this.updateTxt(2);
				}
				this.facade.sendNotification(CLZNoticeName.SHOW_MOVE_TIP, {tip: _loc_3});
			}
			return;
		} 

		private function getRotationLong(param1:int, param2:Number, param3:int, param4:int, param5:int, param6:Number, param7:Number=0):Number
		{
			var _loc_8:*=360 * (Math.floor(Math.random() * (param4 - param3)) + param3);
			var _loc_9:*=360 / param1 * param2;
			var _loc_10:*=360 / param1 * param5;
			var _loc_11:*=Math.floor(Math.random() * (360 / param1) * (1 - 2 * param6)) + 360 / param1 * param6;
			return _loc_8 + _loc_9 + _loc_10 + _loc_11 + param7;
		} 

		private function getCureMc(param1:int, param2:Number):Number
		{
			if (param2 < 0)
			{
				param2=180 + (180 + param2);
			}
			return param2 / (360 / param1);
		} 

		public function updateTxt(param1:int):void
		{
			var xmlList:XMLList;
			var i:uint;
			var attrList:XMLList;
			var value:int;
			var type:*=param1;
			var _loc_4:int=0;
			var _loc_5:*=GameData.lotteryXML.rule;
			var _loc_3:*=new XMLList("");
			var item:*;
//			for each (item in _loc_5)
//			{
//
//				var _loc_7:*=item;
//				with (_loc_6)
//				{
//					if (@rule == type)
//					{
//						_loc_3[_loc_4]=_loc_6;
//					}
//				}
//			}
			xmlList=_loc_3.children();
			i;
			while (i < xmlList.length())
			{

				attrList=xmlList[i].attributes();
				value=attrList[2];
				if (value >= 10000)
				{
					this._arrTxt[i].text=value / 10000 + "W";
				}
				else
				{
					this._arrTxt[i].text=attrList[2].toString();
				}
				this._arrMc[i].gotoAndStop(1);
				i=(i + 1);
			}
			return;
		} 

	}
}
